﻿@model KL.Store.Web.Models.CartModel
@using KL.Store.Core
@{
    Layout = null;
    var dcrImg = "decrase.png";
    var icrImg = "increase.png";
    if (Parameters.Theme == "HA")
    {
        dcrImg = "cart-minus.png";
        icrImg = "cart-plus.png";
    }
    
    
}
@{if (Model.Products.Count == 0)
  {
    <text>Sepetinizde henüz ürün bulunmamaktadır.</text>
  }
  else
  {
    <table class="table-responsive cartMinimalView" style="width: 100%;">
        <thead>
            <tr class="shop-cart-table-head">
                <td class="name" width="65%">Ürün</td>
                <td class="quantity" width="10%">Adet</td>
                <td class="total" width="25%">Ara Toplam</td>
            </tr>
        </thead>
    </table>
    <div id="cartMinimalProducts">
        <table class="table-responsive cartMinimalView" style="width: 100%;">
            <tbody>
                @{
      List<string> kargoUyari = new List<string>();
      List<int> kargoEklenenler = new List<int>();
                }
                @foreach (var item in Model.Products)
                {
                    KL.Store.Core.Domain.CargoDiscount CgDiscount = KL.Store.Data.dbCart.GetCargoDiscountSummary(item.ProductId);
                    if (CgDiscount.SepetMinTutar != 0 && !string.IsNullOrEmpty(Convert.ToString(CgDiscount.SepetMinTutar)) && CgDiscount.SepetMinTutar > (item.Price * item.Qty))
                    {
                        if (!kargoEklenenler.Contains(CgDiscount.IdGrup))
                        {
                            kargoUyari.Add("Sepetinizde bulunan " + CgDiscount.Aciklama + " kategorisindeki ürünlerde " + CgDiscount.SepetMinTutar + " TL ve üzeri alışverişlerinizde kargo ücreti " + (Convert.ToDouble(CgDiscount.KargoUcret) * 1.18).ToString("###,###,##0.00") + " TL’ye sabitlenmektedir. Bu fırsattan yararlanmak ve daha az kargo ücreti ödemek için sepetinize yeni ürünler ekleyebilirsiniz. <br /><a href=\"" + CgDiscount.LinkUrl + "\" class=\"btn btn-custom2 right\">Yeni Ürün Ekle</a>");
                            kargoEklenenler.Add(CgDiscount.IdGrup);
                        }
                    }
                    <tr>
                        <td class="name" width="60%">
                            <a class="hizliBak" href="#quickViewContainer" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount">
                                <table class="productInfo">
                                    <tr>
                                        @if (Model.ShowPhotos)
                                        {
                                            <td>
                                                <div class="cart-minimal-image">
                                                    @if (item.ProductImageCount > 0)
                                                    {
                                                        <img alt="@(item.ProductName.Replace("\"", ""))" src="@(Parameters.WebSiteImageUrl)/product-small/@(item.ProductId)_1.jpg" id="ip_@item.ProductId"  />
                                                    }
                                                    else if (item.ProductImageCount2 > 0)
                                                    {
                                                        <img alt="@(item.ProductName.Replace("\"", ""))" src="@(Parameters.WebSiteImageUrl)/product-small/@(item.UstUrunId)_1.jpg" id="ip_@item.ProductId"  />
                                                    }
                                                    else
                                                    {
                                                        <img alt="@(item.ProductName.Replace("\"", ""))" src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" id="ip_@item.ProductId"  />
                                                    }
                                                </div>
                                            </td>
                                        }
                                        <td>
                                            <span class="nameSpan">
                                                @(item.ProductName + (!string.IsNullOrEmpty(item.Model) ? " - " + item.Model : ""))
                                                @if (item.InstallmentNeeded)
                                                {
                                                    if (item.InstallmentSelected)
                                                    {
                                                    <text><br />
                                                    Kurulum Seçildi (</text>@item.InstallmentPrice.ToString("###,###,##0.00")<text> TL Kdv Dahil)</text>
                                                    }
                                                    else
                                                    {
                                                    <text><br />
                                                    Kurulum Seçilmedi</text>
                                                    }
                                                }
                                                @if (!string.IsNullOrEmpty(item.ListOwner))
                                                {
                                                    <text><br />@item.ListOwner</text>
                                                }
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </a>
                        </td>
                        <td class="quantity" width="20%">
                            @if (Model.ShowAcrIcrLinks)
                            {
                                <a id="mnDcr_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="mnDcrLink">
                                    <i class="glyphicon glyphicon-minus"></i>
                                </a>
                            }
                            @if (item.Qty > 0)
                            {
                                <span data-val="@item.Qty.ToString("#####")" id="mnQty_@(item.ListId)_@(item.ProductId)">@item.Qty.ToString("#####")</span>
                            }
                            else
                            {
                                <text>Hediye Destek</text>
                            }
                            @if (Model.ShowAcrIcrLinks)
                            {
                                <a id="mnIcr_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="mnIcrLink">
                                    <i class="glyphicon glyphicon-plus"></i>
                                </a>
                            }
                        </td>
                        <td class="total" width="20%">@if (item.Qty > 0)
                                                      {
                            @((item.Price * item.Qty).ToString("###,###,##0.00"))
                                                      }
                                                      else
                                                      {
                            @(item.Price.ToString("###,###,##0.00"))
                                                      }  @item.Currency</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    @Html.Raw(ViewData["cartMessage"])
    <script>
        $('a.mnDcrLink').click(function ()
        {
            var qsUserId = $(this).attr('id').split("_")[1];
            var qsId1 = $(this).attr('id').split("_")[2];
            var qsId2 = $(this).attr('id').split("_")[3];
            var qty = $('#mnQty_' + qsId1.toString() + "_" + qsId2.toString()).attr("data-val");
            qty--;
            $('#sepetMinimalContent').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, position: 1, ShowAcrIcrLinks: true });
            $('#checkoutMinimalContent').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, position: 2, showMsg: false, ShowAcrIcrLinks: true });
            if (document.getElementById('checkoutMinimalContent') != null)
            {
                frmSubmit(0)
            }
            $('#cart').load('/Cart/GetSummary2', {});
            $('.contentCart').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, showMsg: false });
            return false;
        });

        $('a.mnIcrLink').click(function ()
        {
            var qsUserId = $(this).attr('id').split("_")[1];
            var qsId1 = $(this).attr('id').split("_")[2];
            var qsId2 = $(this).attr('id').split("_")[3];
            var qty = $('#mnQty_' + qsId1.toString() + "_" + qsId2.toString()).attr("data-val");
            qty++;
            $('#sepetMinimalContent').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, position: 1, ShowAcrIcrLinks: true });
            $('#checkoutMinimalContent').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, position: 2, showMsg: false, ShowAcrIcrLinks: true });
            if (document.getElementById('checkoutMinimalContent') != null)
            {
                frmSubmit(0)
            }
            $('#cart').load('/Cart/GetSummary2', {});
            $('.contentCart').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty, showMsg: false });
            return false;
        });
    </script>
  }
}